import 'package:flutter/material.dart';
import 'package:x3_base_core/x3_base_core.dart';
import '../mixin/advanced_filter_select_mixin_style_two.dart';
import 'package:x3_form_core/models/base_advanced_filter_model.dart';

class AdvancedFilterMultiChoiceStyleTwo extends StatefulWidget {
  final BaseAdvancedFilterModel model;

  const AdvancedFilterMultiChoiceStyleTwo({Key key, @required this.model}) : super(key: key);

  @override
  _AdvancedFilterMultiChoiceStyleTwoState createState() => _AdvancedFilterMultiChoiceStyleTwoState();
}

class _AdvancedFilterMultiChoiceStyleTwoState extends State<AdvancedFilterMultiChoiceStyleTwo> with AdvancedFilterSelectMixinStyleTwo<AdvancedFilterMultiChoiceStyleTwo> {
  @override
  Widget build(BuildContext context) {
    return buildItemContainer();
  }

  @override
  List<BaseKeyValueModel> get children => widget.model.selectData ?? [];

  @override
  BaseAdvancedFilterModel get model => widget.model;

  @override
  void onChange(bool v, BaseKeyValueModel data) {
    /// 如果是勾选全部的话
    if (data.key.toString() == allKey.toString() && v == true) {
      selectedList.clear();
    } else {
      bool isAll = selectedListKey.contains(allKey.toString());
      if (isAll == true) selectedList.removeWhere((element) => element.key.toString() == allKey.toString());
    }
    onChangeEvent(v, data);
    baseRequestFormProvider.setDataSource(this.model, selectedList.map((e) => e.toJson()).toList());
    setState(() {});
  }

}
